<!DOCTYPE html>
<html>
<head>
    <head/>
    <title>医院详情</title>
    <titleType style="display: none;">sc</titleType>
    <%- include('./_global/appendJs') %>
    <script src="/static/lib/forweb.js"></script>
    <script src="/quickJs/scripts/swiper/3.4.2/js/swiper.min.js"></script>
    <script src="/static/js/<%=type%>/pageUrl.js"></script>
    <script src="/static/js/<%=type%>/yygh.js"></script>
</head>
<style>
    .hospital-detail .hospital-jj-box .text-box span.yellow {
        margin-left: 0.5rem !important;
    }
</style>


<body>
<input id="titleType" type="hidden" value="sc">
<section class="page-wrap hospital-detail">
    <header class="header-box grey fixed">
        <div class="header-content">
            <div class="left-tool">
                <a class="back" href="javascript:void(0);"><i class="iconfont icon-back"></i></a>
            </div>
            <!-- <div class="right-tool">
                <a href="javascript:void(0);"><i class="sc-icon"></i></a>
            </div> -->
            <div class="title">医院详情</div>
        </div>
    </header>
    <div class="hospital-jj-box" id="hosDiv">
        <i class="icon-box hosImgUrl"></i>
        <div class="text-box">
            <span class="title hosName"></span>
            <span class="yellow hosLevel"></span>
            <span class="yellow isMedicare"></span>
            <span class="doctorCount"></span>
            <span class="hosAddress"></span>
        </div>
        <!-- <a class="ck-map" href="javascript:void(0)">查看地图</a> -->
    </div>
    <div class="hospital-tab-box">
        <ul class="row" id="ListTab">
            <li class="col-xs-6 active" index="0">
                <a>预约挂号</a>
            </li>
            <li class="col-xs-6" index="1">
                <a>医院简介</a>
            </li>
           <!--  <li class="col-xs-4" index="2">
                <a>排班科室</a>
            </li> -->
        </ul>
    </div>
    <div id="ListTabBox">
        <div class="tab active" index="0">
            <div class="box-left">
                <dl>
                    <dd>
                    </dd>
                </dl>
            </div>
            <div class="box-right">
                <ul>
                </ul>
            </div>
        </div>
        <div class="tab" style="display:none;" index="1">
            <div class="hospital-text-box">
            </div>
        </div>
        <div class="tab" style="display:none;" index="2">
            <table class="pbks-box">
                <tr>
                    <th class="first-th">日期</th>
                    <th>上午（8:00-11:30）</th>
                    <th>下午（13:30-17:00）</th>
                </tr>

            </table>
        </div>
    </div>
</section>
</body>
<script type="text/html" id="ksLi">
    <li><a href="javascript:void(0);"></a></li>
</script>
<script type="text/html" id="pbxxOne">
    <tr>
        <td class="odd-week date"></td>
        <td class="AM"></td>
        <td class="PM"></td>
    </tr>
</script>
<script type="text/html" id="pbxxTwo">
    <tr>
        <td class="even-week date"></td>
        <td class="even-content AM"></td>
        <td class="even-content PM"></td>
    </tr>
</script>
<script type="text/javascript">



    var page_hosDetail = (function($, page_hosDetail) {

        var tb_zy_yyjb = {
            "0": "社区卫生服务中心"
            , "1": "一级"
            , "2": "二级"
            , "3": "三级"
            , "": "未评级"
        };
        var tb_zy_yydj = {
            "0": "特等"
            , "1": "甲等"
            , "2": "乙等"
            , "3": "丙等"
        };

        var sfsc = "";
        var requestRoot = "/jkcsHt/yygh";
        var hosCode = $.QuickUrlUtils.getRequest("hosCode");

        /**加载视图*/
        function initView() {
            /**一级科室点击*/
            $(".box-left").on("click", "a", function () {
                /**脚本改变选中状态*/
                if (!$(this).hasClass("active")) {
                    $(".box-right").show();
                    $(this).addClass("active").siblings().removeClass("active");
                }
                var info = $(this).data("info");
                /**查询二级科室*/
                $.QuickRemote.AjaxJson({
                    funcName:$.getMyorderUrl.getpageUrl("getDeptListTwo")
                    ,callback:function (result) {
                        /**解析二级科室*/
                        var data = result;
                        var lis = [];
                        $(data).each(function (index, item) {
                            var ks = $($("#ksLi").html());
                            $(ks).find("a").html(item["depName"]);
                            $(ks).data("info", item);
                            lis.push(ks);
                        });
                        var ul = $(".box-right").find("ul");
                        $(ul).empty();
                        $(ul).append(lis);
                    }
                    ,params:{hosCode: hosCode, parentCode: info["depCode"]}
                });
            });

            /**二级科室点击跳转*/
            $(".box-right").on("click", "li", function () {
                var info = $(this).data("info");
                StoreCache.setCache("YYGH_KSINFO", info);
                $.pageSwitch.goToUrl("myOrder","ksDetail");
            });

            /**医院信息table切换*/
            $("#ListTab").on("click", "li", function () {
                if (!$(this).hasClass("active")) {
                    $(this).addClass("active").siblings().removeClass("active");
                }
                var index = $(this).attr("index");
                $("#ListTabBox").find(".tab").hide();
                $("#ListTabBox").find(".tab[index='" + index + "']").show();
            });

            /**获取跳转路径参数判断tab切换*/
            var tab = $.QuickUrlUtils.getRequest("HOSDETAIL_TAB");
            if (!StringUtils.isEmpty(tab)) {
                $("#ListTab").find("li[index='" + tab + "']").trigger("click");
            }
            /**收藏按钮*/
            $(".sc-icon").on("click", page_hosDetail.scFunction);
            /**设置收藏使用参数*/
            $(".sc-icon").data("info", {hosCode: hosCode});
            $.JkcsUtils.jsbridgeRegister("scFunction", page_hosDetail.scFunction);

        }

        /**加载数据*/
        function initData() {
            page_hosDetail.getHospitalList();
            page_hosDetail.getDeptListTop();
        }
        function getHospitalList(){
            $.QuickRemote.AjaxJson({
                funcName: $.getMyorderUrl.getpageUrl("getHospitalList")
                ,callback: page_hosDetail.getHospitalListHandler
                ,params:{hosCode: hosCode}
            });
        }
        function getHospitalListHandler(result){
            var hospitals = result['hospitals'];
            if(hospitals.length > 0){
                var hosInfo = hospitals[0];
                $('body').data('hosInfo', hosInfo);
                StoreCache.setCache("YYGH_HOSINFO", hosInfo);
                page_hosDetail.setHosInfo();
            }
        }
        /*设置医院信息*/
        function setHosInfo(){
            var hosInfo = $('body').data('hosInfo');
            var hosDiv = $("#hosDiv");
            var hosImgUrl = hosInfo["hosImgUrl"];
            if(!StringUtils.isEmpty(hosImgUrl)){
                hosDiv.find(".hosImgUrl").attr("style", "background:url('" + hosInfo["hosImgUrl"] + "') no-repeat;background-size: 100% 100%;");
            }
            hosDiv.find(".hosName").text(hosInfo["hosName"]);
            var hosGrade = hosInfo["hosGrade"];
            var hosLevel = hosInfo["hosLevel"];
            hosDiv.find(".hosLevel").text(hosGrade==''?'':tb_zy_yyjb[hosGrade] + hosLevel==''?'':tb_zy_yydj[hosLevel]);
            hosDiv.find(".isMedicare").text(hosInfo["isMedicare"] == "0"?"医保":"非医保");
            hosDiv.find(".doctorCount").text((hosInfo["doctorCount"] == "" ? "0" : hosInfo["doctorCount"]) + " 医生");
            hosDiv.find(".hosAddress").text(hosInfo["hosAddress"]);
            hosDiv.find(".ck-map").on("click", function () {
                var str = hosInfo["hosLocation"];
                if (str) {
                    var strs = str.split(",");
                    var params = {
                        longitude: strs[0],
                        latitude: strs[1],
                        hosName: hosInfo["hosName"]
                    };
                    $.JkcsUtils.gotoMap(params);
                }
            });
            /**添加医院简介*/
            var yyjj = $("<p>").html(hosInfo["hosDesc"]);
            $(".hospital-text-box").append(yyjj);
        }

        function getDeptListTop(){
            $.QuickRemote.AjaxJson({
                funcName:$.getMyorderUrl.getpageUrl("getDeptListTop")
                ,callback:function (result) {
                    /**解析一级科室*/
                    var data = result;
                    var lis = [];
                    $(data).each(function (index, item) {
                        var ks = $("<a>").attr("href", "javascript:void(0);");
                        $(ks).html(item["depName"]);
                        $(ks).data("info", item);
                        lis.push(ks);
                    });
                    var dd = $(".box-left").find("dd");
                    $(dd).empty();
                    $(dd).append(lis);
                    $(dd).find("a:eq(0)").trigger("click");
                }
                ,params:{hosCode: hosCode}
            });
        }

        /**收藏方法*/
        function scFunction() {
            var params = $(".sc-icon").data("info");
            params["sfsc"] = sfsc;
            $.QuickRemote.AjaxJson({
                funcName:"/api"+requestRoot + "/saveYyscInfo"
                ,callback: function (result) {
                    if (result["code"] == "0") {
                        if (sfsc == 0) {
                            sfsc = 1;
                        } else {
                            sfsc = 0;
                        }
                        page_hosDetail.loadScImg();
                    } else {
                        var content = "";
                        if (sfsc == 0) {
                            content = "收藏医院失败！";
                        } else {
                            content = "取消收藏医院失败！";
                        }
                        $.QuickAlert.alertFail({
                            content: content
                        });
                    }
                }
                ,params:params
            });
        }

        /**加载收藏图片*/
        function loadScImg(){
            $.JkcsUtils.loadScImg(sfsc);
        }

        var cfg_def = {
            initView: initView,
            initData: initData,
            getHospitalList: getHospitalList,
            getHospitalListHandler: getHospitalListHandler,
            setHosInfo: setHosInfo,
            getDeptListTop: getDeptListTop,
            scFunction: scFunction,
            loadScImg: loadScImg,
        }

        page_hosDetail.init = function(cfg){
            $.extend(page_hosDetail, cfg_def, cfg);
            page_hosDetail.initData();
            page_hosDetail.initView();

        }

        return page_hosDetail;
    })(jQuery, {});
    


</script>
</html>



